package pl.smath.expression.model;

import junit.framework.TestCase;
import pl.smath.expression.parser.ExpressionParserException;
import pl.smath.expression.parser.text.TextParser;

public class EvaluateTestCase extends TestCase {

	private static final String[][] TEST_DATA = {
		{"2+3", "5"},
		{"2*3", "6"},
		{"2+3^2", "11"},
		{"2/4+3^2", "9.5"},
		{"2+9$2", "5"},
		{"(2+2)^2", "16"},
		{"(2+2)$2", "2"},
		{"(1-4$2)/2", "-0.5"},
	};

	
	/**
	 * Testowanie niemodyfikującego visitor'a
	 * @throws ExpressionParserException 
	 */
	public void testData() throws ExpressionParserException {
		Term expression;
		TextParser parser = new TextParser();
		
		for(int i = 0; i < TEST_DATA.length; i++){
			expression = parser.parse( TEST_DATA[i][0] );

			Term output = expression.evaluate();
			assertEquals( TEST_DATA[i][0], TEST_DATA[i][1], output.toString() );
		}
	}
}
